home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13939 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: prairienet.org!sjmccaug
  2. From: sjmccaug@prairienet.org (Scott J. McCaughrin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help: Can't extract fractional digits of DOUBLE
  5. Date: 28 Mar 1996 00:23:54 GMT
  6. Organization: University of Illinois at Urbana
  7. Message-ID: <4jcm6q$6vm@vixen.cso.uiuc.edu>
  8. References: <4jc9r7$hnf@nuacht.iol.ie> <4jc3cc$5nj@atlas.tncnet.com>
  9. Reply-To: sjmccaug@prairienet.org (Scott J. McCaughrin)
  10. NNTP-Posting-Host: firefly.prairienet.org
  11.  
  12.  
  13. In a previous article, Goyra@iol.ie (David Byrden) says:
  14.  
  15. >Simon Lee (Simon Lee) wrote:
  16. >>
  17. >>Hello everyone,
  18. >>
  19. >>I'm trying to take a double value and extract each digit from the value.
  20. >
  21. >
  22.  How are are you assuming the double's representation -- as a fraction
  23.  or in scientific notation? One way to simplify your task is to take
  24.  advantage of the function 'frexp' which does the following:
  25.  
  26.      Every non-zero number can be written uniquely as x  *  2**n,
  27.      where the significant x is in the range 0.5 <= |x| < 1.0 and
  28.      the exponent n is an integer.  The function frexp()  returns
  29.      the  significand  of a double value as a double quantity, x,
  30.      and stores the exponent  n,  indirectly  through  eptr.   If
  31.      value == 0, both results returned by frexp() are 0.
  32.  
  33.      Here is the prototype: double frexp(double value, int *eptr)
  34.  
  35.  Now at least you have a number x = frexp(value, &n) in the range
  36.  0.5 ... 1 that you can more easily strip digits from than an arb-
  37.  trary double.
  38.  
  39.  
  40.